{% extends 'articles/base.html' %}

{% block title %}{{ article.title }} - Markdown站点{% endblock %}

{% block extra_css %}
<style>
    /* Markdown内容样式 */
    .markdown-content {
        line-height: 1.6;
        color: #333;
        font-size: 16px;
    }
    
    .markdown-content h1,
    .markdown-content h2,
    .markdown-content h3,
    .markdown-content h4,
    .markdown-content h5,
    .markdown-content h6 {
        margin-top: 24px;
        margin-bottom: 16px;
        font-weight: 600;
        line-height: 1.25;
    }
    
    .markdown-content h1 {
        padding-bottom: 0.3em;
        font-size: 2em;
        border-bottom: 1px solid #eaecef;
    }
    
    .markdown-content h2 {
        padding-bottom: 0.3em;
        font-size: 1.5em;
        border-bottom: 1px solid #eaecef;
    }
    
    .markdown-content p {
        margin-top: 0;
        margin-bottom: 16px;
    }
    
    .markdown-content ul,
    .markdown-content ol {
        padding-left: 2em;
        margin-top: 0;
        margin-bottom: 16px;
    }
    
    .markdown-content li {
        margin-bottom: 0.25em;
    }
    
    .markdown-content blockquote {
        padding: 0 1em;
        color: #6a737d;
        border-left: 0.25em solid #dfe2e5;
        margin: 0 0 16px 0;
    }
    
    .markdown-content pre {
        padding: 16px;
        overflow: auto;
        font-size: 85%;
        line-height: 1.45;
        background-color: #f6f8fa;
        border-radius: 3px;
        margin-bottom: 16px;
    }
    
    .markdown-content code {
        font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;
        background-color: rgba(27,31,35,0.05);
        border-radius: 3px;
        padding: 0.2em 0.4em;
        font-size: 85%;
    }
    
    .markdown-content pre code {
        background-color: transparent;
        padding: 0;
        border-radius: 0;
    }
    
    .markdown-content table {
        border-collapse: collapse;
        margin: 16px 0;
        width: 100%;
        display: block;
        overflow: auto;
    }
    
    .markdown-content table th {
        font-weight: 600;
        padding: 6px 13px;
        border: 1px solid #dfe2e5;
    }
    
    .markdown-content table td {
        padding: 6px 13px;
        border: 1px solid #dfe2e5;
    }
    
    .markdown-content img {
        max-width: 100%;
        box-sizing: content-box;
        background-color: #fff;
    }
    
    /* 文章元信息样式 */
    .article-meta {
        color: #666;
        font-size: 0.9em;
        margin-bottom: 20px;
        padding-bottom: 10px;
        border-bottom: 1px solid #eee;
    }
    
    /* 响应式调整 */
    @media (max-width: 768px) {
        .markdown-content {
            font-size: 15px;
            padding: 0 10px;
        }
    }
</style>
{% endblock %}

{% block content %}
<article class="article-container">
    <header class="article-header">
        <h1 class="article-title">{{ article.title }}</h1>
        <div class="article-meta">
            <span>发布于: {{ article.created_at|date:"Y-m-d H:i" }}</span>
            {% if article.updated_at != article.created_at %}
            <span> | 更新于: {{ article.updated_at|date:"Y-m-d H:i" }}</span>
            {% endif %}
            {% if article.author %}
            <span> | 作者: {{ article.author }}</span>
            {% endif %}
        </div>
    </header>
    
    <div class="markdown-content">
        {{ article.content|safe }}
    </div>
    
    <footer class="article-footer">
        {% if article.tags.all %}
        <div class="article-tags">
            <span>标签:</span>
            {% for tag in article.tags.all %}
            <a href="{% url 'articles:tag_detail' tag.slug %}" class="tag">{{ tag.name }}</a>
            {% endfor %}
        </div>
        {% endif %}
    </footer>
</article>
{% endblock %}

{% block extra_js %}
<script>
// 可以在这里添加文章页特有的JavaScript
document.addEventListener('DOMContentLoaded', function() {
    // 为所有标题添加锚点链接
    document.querySelectorAll('.markdown-content h1, .markdown-content h2, .markdown-content h3').forEach(function(heading) {
        if (heading.id) {
            var anchor = document.createElement('a');
            anchor.className = 'header-anchor';
            anchor.href = '#' + heading.id;
            anchor.innerHTML = '#';
            heading.appendChild(anchor);
        }
    });
    
    // 表格响应式处理
    document.querySelectorAll('.markdown-content table').forEach(function(table) {
        var wrapper = document.createElement('div');
        wrapper.className = 'table-responsive';
        table.parentNode.insertBefore(wrapper, table);
        wrapper.appendChild(table);
    });
});
</script>
{% endblock %}
